﻿@using Newtouch.Infrastructure;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
    //住院记账是否可以记药品
    var isacountingPageMayMedicine =
        SysConfigReader.Bool("HOSP_AccountingPage_May_Medicine", true).Value;
    //药品检索，药品是否关联药房库存
    var isMedicineSearchRelatedKC = (ViewBag.ISMedicineSearchRelatedKC as bool?) ?? false;
}

<style>
    .napan {
        color: red;
    }
</style>
<div class="rows" style="margin-bottom: 1%;">
    <div class="panel panel-default" style="margin-bottom:0;">
        <div class="panel-heading navb-bg">
            住院患者信息
        </div>
        <table class="form" style="width:96%;">
            <tbody>
                <tr>
                    <th class="formTitle">住院号：</th>
                    <td class="formValue">
                        <input class="form-control" type="text" id="zyh" value="" />
                    </td>
                    <td class="formValue">
                        <input type="button" class="btn btn-default btn-md btn-default-color" title="选择住院患者" id="zy_btnsyy" value="查询" onclick="GetPatSerarchView();">
                    </td>
                    <th class="formTitle">姓名：</th>
                    <td class="formValue">
                        <label id="xm"></label>
                    </td>
                    <th class="formTitle">性别：</th>
                    <td class="formValue">
                        <label id="xb"></label>
                    </td>
                    <th class="formTitle">年龄：</th>
                    <td class="formValue">
                        <label id="nlshow"></label>
                    </td>
                    <th class="formTitle">证件号：</th>
                    <td class="formValue">
                        <label id="zjh"></label>
                    </td>
                </tr>
            </tbody>
            <tbody class="dispTbody" style="display:none;">
                <tr>
                    <th class="formTitle">入院诊断：</th>
                    <td class="formValue" colspan="2">
                        <label id="ryzd"></label>
                    </td>
                    <th class="formTitle">手机号：</th>
                    <td class="formValue">
                        <label id="phone"></label>
                    </td>
                    <th class="formTitle">出生日期：</th>
                    <td class="formValue">
                        <label id="csny"></label>
                    </td>
                    <th class="formTitle">入院日期：</th>
                    <td class="formValue">
                        <label id="ryrq"></label>
                        <label id="cyrq" hidden></label>
                        <label id="cqrq" hidden></label>
                        <label id="ztjsrq" hidden></label>
                    </td>
                </tr>
            </tbody>
        </table>
        <div class="fa_icontoggle"><i class="fa fa-angle-double-down icontoggle" style="color:rgb(0, 160, 233);cursor:pointer;"></i></div>
    </div>
</div>
<div id="BookKeep" class="rows" style="margin-bottom:1%;">
    <div class="panel panel-default" style="margin-bottom: 0;">
        <div class="panel-heading navb-bg">
            记账项目
        </div>
        <table class="form">
            <tr>
                <td class="formTitle">
                    <span class="napan">*</span>记账日期：
                </td>
                <td class="formValue">
                    <input id="jzrq" type="text" class="form-control input-wdatepicker formClearIgnore" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" />
                </td>
                <td class="formTitle">
                    <span class="napan">*</span>医生：
                </td>
                <td class="formValue">
                    <input type="text" id="doctor" class="form-control form-an formClearIgnore" />
                </td>
                <td class="formTitle">
                    <span class="napan">*</span>科室：
                </td>
                <td class="formValue">
                    <input type="text" id="jzks" class="form-control formClearIgnore" />
                </td>
                <td class="formTitle">
                    执行科室：
                </td>
                <td class="formValue">
                    <input type="text" id="zxks" class="form-control formClearIgnore" />
                </td>
            </tr>
            <tr>
                <td class="formTitle">
                    <span class="napan">*</span>收费项目：
                </td>
                <td class="formValue">
                    <input id="sfxmmc" type="text" class="form-control form-an" />
                    <input id="sfxmCode" type="text" style="display:none;" class="form-control" />
                    <input id="sfdlCode" type="text" style="display:none;" class="form-control" />
                    <input id="sfdlmc" type="text" style="display:none;" class="form-control" />
                    <!-- 医嘱类型 2项目 1药品 -->
                    <input id="yzlx" type="text" style="display:none;" class="form-control" />
                    <input id="yfdm" type="text" style="display:none;" class="form-control" />
                    <input id="zfbl" type="text" style="display:none;" class="form-control" />
                    <input id="zfxz" type="text" style="display:none;" class="form-control" />
                    <input id="cls" type="text" style="display:none;" class="form-control" />
                </td>
                <td class="formTitle">
                    <span class="napan">*</span>数量：
                </td>
                <td class="formValue">
                    <input type="text" id="sl" class="form-control form-an" />
                </td>
                <td class="formTitle">
                    单位：
                </td>
                <td class="formValue">
                    <label id="dw"></label>
                </td>
                <td class="formTitle">
                    单价(元)：
                </td>
                <td class="formValue">
                    <label id="dj"></label>
                </td>
            </tr>
        </table>
    </div>
</div>
@Html.Partial("_MiddleButtonsView", new Newtouch.HIS.Web.Core.Models.BottomButtonViewModel()
{
    ShowKeyList = new int[] { 2, 3, 6, 9 },
    F2Text = "添加",
    F3Text = "修改",
    F6Text = "删除",
    F9Text = "取消修改",
    F9Hidden = true
})
<div class="gridPanel">
    <table id="gridList"></table>
</div>
@Html.Partial("_BottomButtonsView", new Newtouch.HIS.Web.Core.Models.BottomButtonViewModel
{
    ShowKeyList = new int[] { 4, 7, 8 },
    F7Text = "模板",
})

<script>
    var requestfrom = $.request("requestfrom");
    var xmjf = [];
    var selectedZyh = null;
    var editingNewid = null;

    $(function () {
        initControl();
        gridListData();
    });

    //回车查询
    $('#zyh').keydownEnterEvent(function() {
        getPatInfoAjax({ zyh: $('#zyh').val() });
    });

    //病人查询(住院)
    function GetPatSerarchView() {
        $.modalOpen({
            id: "patSearch",
            title: "患者查询",
            url: "/PatientManage/AccountManage/PatSearchView?brzybzType=" + '@((int)EnumZYBZ.Xry + "," + (int)EnumZYBZ.Bqz + "," + (int)EnumZYBZ.Djz)' + "&t=" + Math.random() + "&zyh=" + '',
            width: "700px",
            height: "600px",
            callBack: function (iframeId) {
                top.frames[iframeId].PatDbGrid(); //在弹出窗口事件
                //调用查询卡号和住院号
            }//窗口点确定的回调函数
        });
    }

    //选择的病人 callback
    function getPatInfoAjax(selePatInfo) {
        //清一下
        newtouch_globalevent_f4();
        //
        if (selePatInfo && selePatInfo.zyh) {
            selectedZyh = selePatInfo.zyh;
            $('#zyh').val(selePatInfo.zyh);
            ajaxLoadDataResult(selectedZyh);
        }
        else {
            selectedZyh = '';
            $('#zyh').val('');
        }
    }

    //仅清除输入域的内容
    function clearJZInfo() {
        newtouch_globalevent_f4(null, {
            container: "#BookKeep",
            inner: false
        });
    }

    //删除其中一条数据
    function delData() {
        var $gridList = $("#gridList");
        var id = $gridList.jqGrid("getGridParam", "selrow");
        if (id) {
            var rowData = $("#gridList").jqGrid('getRowData', id);
            var matchedIndex = -1;
            if (xmjf.length > 0) {
                for (var ii = 0; ii < xmjf.length; ii++) {
                    if (xmjf[ii].newid === rowData.newid) {
                        matchedIndex = ii;
                    }
                }
            }
            if (matchedIndex === -1) {
                return; //应该是异常
            }
            xmjf.remove(matchedIndex);   //移除新记账
            fillDataToGrid();
        }
        else {
            $.modalAlert("请选中一条数据！", 'error');
        }
    }

    //重新绑定grid
    function fillDataToGrid() {
        $('#gridList').jqGrid("clearGridData");
        $("#gridList").newtouchLocalDataGrid(null, xmjf);
    }

    //绑定grid
    function gridListData() {
        var $gridList = $("#gridList");
        $gridList.newtouchLocalDataGrid({
            height: $(window).height() - 330,
            unwritten: false,
            colModel: [
                { label: "主键", name: "newid", hidden: true, key: true },
                { label: '收费项目', name: 'sfxmmc', width: 250, align: 'left', editor: "text" },
                { label: '费用类别', name: 'dlmc', width: 100, align: 'left', editor: "text" },
                { label: '单位', name: 'dw', width: 100, align: 'left', editor: "text" },
                {
                    label: '单价', name: 'dj', width: 100, align: 'left', editor: "text", formatter: "number"
                    , formatoptions: { decimalPlaces: 4, defaultValue: '0.0000' }
                },
                { label: '数量', name: 'sl', width: 100, align: 'left', editor: "text" },
                { label: '金额', name: 'je', width: 100, align: 'left', editor: "text" },
                { label: '科室', name: 'ksmc', width: 100, align: 'left', editor: "text" },
                { label: '医生', name: 'ysmc', width: 100, align: 'left', editor: "text" },
                { label: 'ks', name: 'ks', hidden: true },
                { label: 'ys', name: 'ys', hidden: true },
                { label: 'dl', name: 'dl', hidden: true },
                { label: '自负性质', name: 'zfxz', width: 100, align: 'left', editor: "text", hidden: true },
                { label: '自付比例', name: 'zfbl', width: 100, align: 'left', editor: "text", hidden: true },
                { label: 'sfxm', name: 'sfxm', hidden: true },
                { label: 'yzlx', name: 'yzlx', hidden: true },
                { label: 'yfdm', name: 'yfdm', hidden: true },
                { label: 'cls', name: 'cls', hidden: true }
            ],
            onSelectRow: function (rowid) {
                $('#btn_bottombutton_f3').removeAttr('disabled');
                $('#btn_bottombutton_f6').removeAttr('disabled');
            },
            ondblClickRow: function (rowid) {
                gridEditRow(rowid);
            },
        });
    }

    //加载住院基本信息
    function ajaxLoadDataResult(zyh) {
        $.najax({
            type: "GET",
            url: "/HospitalizationManage/BookkeepInHos/GetAccountingStatusDetail?zyh=" + zyh,
            success: function (ajaxresp) {
                var patModel = ajaxresp.data.patInfo;
                var ztjs = ajaxresp.data.zjrq
                $('#xm').html(patModel.xm);
                $('#xb').html($.getGender(patModel.xb));
                $('#nlshow').html(getAgeFromBirthTime({ begin: patModel.csny }).text);
                $('#ryzd').html(patModel.ryzdmc);
                $('#zjh').html(patModel.zjh);
                $('#phone').html(patModel.phone);
                $('#csny').html(patModel.csny ? patModel.csny.replace("T", " ").substring(0, 16) : '');
                $('#ryrq').html(patModel.ryrq ? patModel.ryrq.replace("T", " ").substring(0, 16) : '');
                $('#cyrq').html(patModel.cyrq ? patModel.cyrq.replace("T", " ").substring(0, 16) : '');
                $('#cqrq').html(patModel.cqrq ? patModel.cqrq.replace("T", " ").substring(0, 16) : '');
                $("#doctor").val(patModel.ysmc);
                $("#doctor").attr("data-label", patModel.ysgh);
                $("#jzks").attr("data-label", patModel.ksCode);
                $("#jzks").val(patModel.ksmc);
                $('#ztjsrq').html(ztjs ? ztjs.replace("T", "") : '');
            },
            errorCallback: function (err) {
                newtouch_globalevent_f4();
                $('#zyh').trigger('focus');
            }
        });
    }

    //加载收费项目，医生下拉框的值
    function initControl() {
        $("#jzrq").val($.getDate());
        //收费项目 浮层
        var searchType = "sfxm";
        var dllb = '2';
        if ('@(isacountingPageMayMedicine ? "true" : "")' == 'true') {
            searchType += ',yp';
            dllb += ",1";
            if ('@(isMedicineSearchRelatedKC ? "true" : "")' == 'true') {
                searchType += '.kc';
            }
        }
        $("#sfxmmc").sfxmFloatingSelector({
            djDecimalPlaces: 4,
            searchType: searchType,
            ajaxparameters: function ($thisinput) {
                return "mzzybz=2&dllb=" + dllb + "&keyword=" + $thisinput.val();
            },
            itemdbclickhandler: function ($thistr) {
                if (!selectedZyh) {
                    $.modalAlert("病人基本信息不能为空", 'warning');
                    return;
                }
                $("#sfxmmc").val($thistr.attr('data-sfxmmc'));
                $('#dw').html($thistr.attr('data-dw'));
                $("#dj").html($thistr.attr('data-dj'));
                $('#sfxmCode').val($thistr.attr('data-sfxmCode'));
                $('#sfdlCode').val($thistr.attr('data-sfdlCode'));
                $('#sfdlmc').val($thistr.attr('data-sfdlmc'));
                $('#yzlx').val($thistr.attr('data-yzlx'));
                $('#zfxz').val($thistr.attr('data-zfxz'));
                $('#zfbl').val($thistr.attr('data-zfbl'));
                $('#yfdm').val($thistr.attr('data-yfbmCode'));
                $('#cls').val($thistr.attr('data-cls'));
                if ($("#yzlx").val() == "1") //若为药品则默认药房为执行科室
                {
                    $("#zxks").val("");
                  
                }
                return;
            }
        });

        $('#jzks').newtouchFloatingSelector({
            width: 400,
            height: 180,
            caption: "科室",
            clickautotrigger: true,
            url: '/OutpatientManage/OutpatientRegSchedule/GetSysDepartmentList',
            ajaxmethod: 'POST',
            ajaxreqdata: function () {
                var reqData = {};
                reqData.keyword = '@ViewBag.staffDept';
                return reqData;
            },
            itemdbclickhandler: function ($thistr) {
                $('#jzks').attr('data-label', $thistr.attr('data-code'))
                    .val($thistr.attr('data-Name'));
            },
            colModel: [{ label: '代码', name: 'Code', widthratio: 30 },
            { label: '科室名称', name: 'Name', widthratio: 30 },
            { label: '拼音', name: 'py', widthratio: 30 }
            ]
        });
        ///医生
        $("#doctor").newtouchFloatingSelector({
            height: 240,
            width: 500,
            focusautotrigger: true,
            filter: function (keyword) {
                if (!selectedZyh) {
                    $.modalAlert("病人基本信息不能为空", 'warning');
                    return;
                }
                //遍历数据源，用keyword来筛选出结果
                var resultObjArr = new Array();
                if (!!top.window.clients.doctorInHosBookkeep) {
                    $.each(top.window.clients.doctorInHosBookkeep, function (idx, val) {
                        if (keyword.trim() == "" || (val.py && val.py.indexOf(keyword.toUpperCase()) >= 0)
                            || (val.StaffName && val.StaffName.indexOf(keyword.toUpperCase()) >= 0)
                            || (val.StaffGh && val.StaffGh.indexOf(keyword.toUpperCase()) >= 0)
                            || (val.ks && val.ks.indexOf(keyword.toUpperCase()) >= 0)
                            || (val.ksmc && val.ksmc.indexOf(keyword.toUpperCase()) >= 0)) {
                            resultObjArr.push(val);
                        }
                    });
                }

                return resultObjArr;
            },
            caption: "医生科室对照",
            colModel: [
                { label: '人员名称', name: 'StaffName', widthratio: 25 },
                { label: '人员工号', name: 'StaffGh', widthratio: 25 },
                { label: '科室名称', name: 'ksmc', widthratio: 25 },
                { label: '科室编码', name: 'ks', widthratio: 25 },
            ],
            itemdbclickhandler: function ($thistr) {
                $("#doctor").val($thistr.attr('data-StaffName'));
                $("#doctor").attr("data-label", $thistr.attr('data-StaffGh'));
                $("#jzks").attr("data-label", $thistr.attr('data-ks'));
                $("#jzks").val($thistr.attr('data-ksmc'));
                return;
            }
        });
        $("#doctor").prop('disabled', 'disabled');

        $("#zxks").newtouchBatchFloatingSelector({
            height: 150,
            width: 250,
            clickautotrigger: true,
            filter: function (keyword) {
                //遍历数据源，用keyword来筛选出结果
                if (!keyword) {
                    keyword = '@ViewBag.staffDeptName';
                }
                var resultObjArr = new Array();
                $.each(top.window.clients.sysDepartList, function (idx, val) {
                    if ((val.py && val.py.toLowerCase().indexOf(keyword.toLowerCase()) >= 0)
                        || (val.Name && val.Name.indexOf(keyword) >= 0)
                        || keyword.trim() == "") {
                        resultObjArr.push(val);
                    }
                });
                return resultObjArr;
            },
            caption: "科室",
            colModel: [
                { label: '编号', name: 'Code', widthratio: 50 },
                { label: '名称', name: 'Name', widthratio: 50 },
                { label: '拼音', name: 'py', hidden: true }
            ],
            itemdbclickhandler: function ($thistr) {
                $("#zxks").attr("data-label", $thistr.find("td:eq(0)").html());
                $("#zxks").val($thistr.find('td:eq(1)').html());
                return;
            },
        });
        $("#zxks").val('@ViewBag.staffDeptName');
        $("#zxks").attr("data-label", '@ViewBag.staffDept');
    }
    

    //保存操作
    function btn_Save() {
        debugger 
        if (!selectedZyh) {
            $.modalAlert("病人基本信息不能为空", 'warning');
            return;
        }
        $.najax({
            url: "/HospitalizationManage/BookkeepInHos/AddData",
            data: { zyh: $('#zyh').val(), ItemFeeVO: xmjf },
            dataType: 'json',
            type: "POST",
            //async: false,
            success: function (data) {
                if (data.message == "保存成功！") {
                    $.modalAlert(data.message, 'success');
                    newtouch_globalevent_f4();
                    $('#zyh').trigger('focus');
                }
                else {
                    $.modalAlert(data.message, 'error');
                }
            },
            error: function (err) {
                $.modalAlert(err, 'error');
            }
        });
    }

    //选择模板
    function GetTemplate() {
        if (!selectedZyh) {
            $.modalAlert("病人基本信息不能为空", 'warning');
            return;
        }
        var ys = $("#doctor").val();
        var ks = $("#jzks").val();
        var kscode = $("#jzks").attr("data-label");

        var url = "/HospitalizationManage/BookkeepInHos/ChargeItemTemplate?keyValue=";
        if (kscode == '@ViewBag.OperationDeptConfig' && requestfrom =="OR") {
            url = "/HospitalizationManage/BookkeepInHos/ChargeItemTemplate?keyValue=" + kscode;
        }
        if (ys && ks && $('#doctor').attr("data-label") && $('#jzks').attr("data-label")) {
            $.modalOpen({
                id: "Form",
                title: "收费项目模板窗口",
                url: url,
                width: "700px",
                height: "530px",
                callBack: function (iframeId) {
                    var data = top.frames[iframeId].submitForm();
                    if ($("#jzks").val() == null || $("#doctor").val() == null) {
                        $.modalAlert("请先选择好医生和科室！", 'warning');
                        return;
                    }
                    $.each(data, function () {
                        var newRowData = {
                            newid: Math.random().toString() + new Date().getMilliseconds(),
                            sl: this.sl,
                            je: roundingBy4she6ru5chengshuang(this.sl * this.dj, 2),
                            tdrq: $("#jzrq").val(),
                            ksmc: $('#jzks').val(),
                            ks: $('#jzks').attr("data-label"),
                            ys: $('#doctor').attr("data-label"),
                            zxks: '@ViewBag.staffDept',
                            zxksmc: '@ViewBag.staffDeptName',
                            ysmc: $('#doctor').val(),
                            dl: this.dl,
                            dlmc: this.dlmc,
                            sfxm: this.sfxm,
                            sfxmmc: this.sfxmmc,
                            dw: this.dw,
                            dj: this.dj,
                            yzlx: 2,    //2项目
                            zfbl: this.zfbl,
                            zfxz: this.zfxz,
                            //cls: this.cls,
                            //yfdm: this.yfdm,
                        };
                        xmjf.unshift(newRowData);   //作为新项添加 //”数组最前端“
                    });
                    //重新将xm数组呈现至grid
                    fillDataToGrid();
                }
            });
        }
        else {
            $.modalAlert("请先选择好医生！", 'warning');
        }
    }

    function newtouch_event_f4() {
        $('#gridList').jqGrid("clearGridData");   //清除所有行

        selectedZyh = null;
        xmjf = [];
        editingNewid = null;
    }

    function newtouch_event_f8() {
        btn_Save();
    }

    function newtouch_event_f7() {
        GetTemplate();
    }

    function newtouch_event_f6() {
        delData();
    }

    function newtouch_event_f2() {
        debugger 
        var newRowData = getEditRowData();
        if (!(checkEditingRowData(newRowData))) {
            //数据是否完善，检查必填项
            return;
        }

        newRowData.newid = Math.random().toString() + new Date().getMilliseconds();

        xmjf.unshift(newRowData);   //作为新项添加 //”数组最前端“
        fillDataToGrid();
        clearJZInfo();

        setTimeout("$('#sfxmmc').trigger('focus');$('#sfxmmc').trigger('click');", 100);
    }

    $('#sl').keydownEnterEvent(function (event) {
        if ($('#sl').hasClass('form-an-cur')) { //缺陷-由上一个enter过来的
            $('#sl').removeClass('form-an-cur')
            return;
        }
        if (editingNewid) {
            $('#btn_bottombutton_f3').trigger('click');
        }
        else {
            $('#btn_bottombutton_f2').trigger('click');
        }
        return false;
    });

    //请求 编辑 行
    function gridEditRow(rowid) {
        if (rowid) {
            var rowData = $("#gridList").jqGrid('getRowData', rowid);
            if (rowData) {
                rowDataArr = $.jsonWhere(xmjf, function (v) {
                    return v && v.newid == rowData.newid;
                });
                if (!rowDataArr || rowDataArr.length == 0) {
                    return; //为什么没找到
                }
                rowData = rowDataArr[0];  //通过rowData.newid从对象数组中取出该行数据
                editingNewid = rowData.newid;    //正在修改的行
                //序列化至编辑域中
                $('#sl').val(rowData.sl);
                $('#jzks').val(rowData.ksmc);
                $('#jzks').attr('data-label', rowData.ks);
                $('#zxks').val(rowData.zxksmc);
                $('#zxks').attr('data-label', rowData.zxks);
                $('#doctor').val(rowData.ysmc);
                $('#doctor').attr('data-label', rowData.ys);
                $('#sfdlCode').val(rowData.dl);
                $('#sfdlmc').val(rowData.dlmc);
                $('#sfxmmc').val(rowData.sfxmmc);
                $('#sfxmCode').val(rowData.sfxm);
                $('#dw').html(rowData.dw);
                $('#dj').html(rowData.dj);
                $('#yzlx').val(rowData.yzlx);
                $('#zfxz').val(rowData.zfxz);
                $('#zfbl').val(rowData.zfbl);
                $('#cls').val(rowData.cls);
                $('#yfdm').val(rowData.yfdm);
                if (!!rowData.tdrq) {
                    $('#jzrq').val($.getDate({ date: rowData.tdrq, ute: true }));
                }

                $('#btn_bottombutton_f6').attr('disabled', 'disabled');
                $('#btn_bottombutton_f9').show();

                $('#btn_bottombutton_f2').attr('disabled', 'disabled');
            }
        }
    }

    //修改按钮
    function newtouch_event_f3() {
        if (editingNewid) {
            //提交修改
            var data = getEditRowData();
            if (!(checkEditingRowData(data))) {
                //数据是否完善，检查必填项
                return;
            }
            var updategoon = function () {
                data.newid = editingNewid;
                //检查重复项

                //先在xm数组中找到之
                var matchedIndex = -1;
                for (var ii = 0; ii < xmjf.length; ii++) {
                    if (xmjf[ii].newid == data.newid) {
                        matchedIndex = ii;
                        break;
                    }
                }
                if (matchedIndex == -1) {
                    return; //应该是异常
                }
                xmjf.remove(matchedIndex);   //移除该项
                xmjf.unshift(data);   //作为新项添加    //”数组最前端“

                //重新将xm数组呈现至grid
                fillDataToGrid();

                clearJZInfo();

                editingNewid = null;    //正在修改的行

                bottomButtonsReset();

                setTimeout("$('#sfxmmc').trigger('focus');$('#sfxmmc').trigger('click');", 100);
            }
            if (data && (parseFloat(data.dj) < '0' || parseFloat(data.dj) == '0')) {
                $.modalConfirm("单价为0，确认是否修改", function (flag) {
                    if (!flag) {
                        return;
                    }
                    else {
                        updategoon();
                    }
                });
            }
            else {
                updategoon();
            }
        }
        else {
            //申请修改 获取grid当前选中的那一行
            var seleId = $('#gridList').jqGrid('getGridParam', 'selrow');
            if (seleId) {
                //请求修改该行
                gridEditRow(seleId);
            }
        }
    }

    //获取编辑域的对象数据
    function getEditRowData() {
        var data = {
            sl: $('#sl').val(),
            je: '',
            tdrq: $('#jzrq').val() +" "+ new Date().toLocaleTimeString('chinese', { hour12: false }),
            ksmc: $('#jzks').val(),
            ysmc: $('#doctor').val(),
            ys: $('#doctor').attr("data-label"),
            ks: $('#jzks').attr("data-label"),
            zxks: $('#zxks').attr("data-label"),
            zxksmc: $('#zxks').val(),
            dl: $('#sfdlCode').val(),
            dlmc: $('#sfdlmc').val(),
            sfxm: $('#sfxmCode').val(),
            sfxmmc: $('#sfxmmc').val(),
            dw: $('#dw').html(),
            dj: $('#dj').html(),
            yzlx: $('#yzlx').val(),
            zfxz: $('#zfxz').val(),
            zfbl: $('#zfbl').val(),
            cls: $('#cls').val(),
            yfdm: $('#yfdm').val(),
            ztsl: $('#sl').val()
        };
        if (data.dj && data.sl) {
            data.je = roundingBy4she6ru5chengshuang((parseFloat(data.sl) * parseFloat(data.dj)), 2);
        }
        return data;
    }

    //检查正在编辑的数据（待提交）的完整性
    function checkEditingRowData(rowData) {
        var ryrq = new Date($('#ryrq').html());
        var cyrq = new Date($('#cyrq').html());
        var cqrq = new Date($('#cqrq').html());
        var cqrq = $('#cqrq').html();
        var ztjsrq = new Date($('#ztjsrq').html());
        if (!rowData.tdrq) {
            $.modalAlert("请选择记账日期", 'warning');
        } else if (ryrq > new Date(rowData.tdrq)) {
            $.modalAlert("记账日期不在住院期间<br/>入院日期：" + $('#ryrq').html(), 'warning');
        } else if (!!cyrq && cyrq < new Date(rowData.tdrq) && ryrq) {
            $.modalAlert("记账日期不在住院期间<br/>出院日期：" + $('#cyrq').html(), 'warning');
        } else if (!!cqrq && cqrq < new Date(rowData.tdrq)) {
            $.modalAlert("记账日期不能晚于出区日期<br/>出区日期：" + $('#cqrq').html(), 'warning');
        }
        else if (!!ztjsrq && ztjsrq < new Date(rowData.tdrq)) {
            $.modalAlert("记账日期不能晚于中途结算日期<br/>中途结算日期：" + $('#ztjsrq').html(), 'warning');
        }
        else if (!rowData.ksmc || !rowData.ysmc || !rowData.ys || !rowData.ks) {
            $.modalAlert("请选择医生", 'warning');
        }
        else if (!rowData.dl || !rowData.dlmc || !rowData.sfxm || !rowData.sfxmmc
            || !rowData.dw) {
            $.modalAlert("请选择收费项目", 'warning');
        }
        else if (!rowData.dj) {
            $.modalAlert("缺少项目单价信息", 'warning');
        }
        else if (!rowData.yzlx) {
            $.modalAlert("缺少医嘱类型", 'warning');
        }
        else if (rowData.yzlx == "2" && (!rowData.zxksmc || !rowData.zxks)) {
            $.modalAlert("请选择执行科室", 'warning');
        }
        else if (!rowData.sl) {
            $.modalAlert("请输入数量", 'warning');
        }
        //手术系统来源则允许小数位
        else if (requestfrom == "OR") {
            if (!((/^[0-9]+([.]{1}[0-9]{1,2})?$/).test(rowData.sl)) || rowData.sl < 0) {
                $.modalAlert("数量为整数或小数点后两位", 'warning');
            } else {
                return true;
            }
        }
        else if (!((/^[0-9]+([.]{1}[0-9]{1,2})?$/).test(rowData.sl)) || rowData.sl < 0) {
            $.modalAlert("数量为整数或小数点后两位", 'warning');
        } 
        else {
            return true;
        }
        return false;
    }

    //按钮重置
    function bottomButtonsReset() {
        $('#btn_bottombutton_f2').removeAttr('disabled');
        $('#btn_bottombutton_f3').attr('disabled', 'disabled');
        $('#btn_bottombutton_f6').attr('disabled', 'disabled');
        $('#btn_bottombutton_f9').hide();
    }

    //F9取消修改
    function newtouch_event_f9() {
        clearJZInfo();

        editingNewid = null;    //正在修改的行

        $("#gridList").resetSelection();

        bottomButtonsReset();

        setTimeout("$('#sfxmmc').trigger('focus');$('#sfxmmc').trigger('click');", 100);
    }

</script>